<?php

namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use App\Models\Goods;
use App\Models\GoodsImage;
use App\Models\DispatchOrder as Order;
class SortingPerMonthSheet implements FromQuery,WithTitle,WithHeadings
{
    private $month;
    private $year;
    public function __construct(int $year, int $month)
    {
        $this->month = $month;
        $this->year = $year;
    }
    public function headings(): array
    {
        $arr= [
            [   '序号',
                '名称',
                '别名'
            ],
            [
                '序号',
                '名称'
            ],
            [
                '序号'
            ],
        ];
        return $arr[$this->month];
    }
    /**
     * @return Builder
     */
    public function query()
    {
        $strif=[
            [
                'goods.id',
                'name',
                'byname'
            ],
            [
                'id',
                'name'
            ],
            [
                'id'
            ]
        ];
        $are=Goods::query()->select($strif[$this->month]);//->leftjoin('goods_images', 'goods.id' ,'=','goods_images.goods_id')
        return $are;
    }
    /**
     * sheet 表名称
     * @return string
     */
    public function title(): string
    {
        return 'Month ' . $this->month;
    }

}